<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button>开关灯</button>
    <script>
        var but = document.querySelector('button');
        var bd = document.body;
        var flage = 1;
        but.onclick = function(){
            if(flage == 1){
                bd.style.backgroundColor='black';
                flage = 0;
            }else{
                bd.style.backgroundColor='#fff';
                flage = 1
            }
        }
    </script>
</body>
</html>